#!/usr/bin/perl

$lex[0] = $ARGV[0];
$cat[0] = $ARGV[1];
$gen[0] = $ARGV[2];
$num[0] = $ARGV[3];
$per[0] = $ARGV[4];
$cases[0] = $ARGV[5];
$tam[0] = $ARGV[6];

$root=@lex[0];
if($tam[0] eq "@0" and $tam[0] eq "@")
{
	$tam[0] = 0;
}
$old_tam = $tam[0];

($tam[0]) = split(/_/,$old_tam);
#				if($root ne "" and $root !~ /^@/ and $tam[0] !~ /^@/)



if($root ne "" and $root !~ /^@/ )
{
	if(@tam[0] ne "")
	{
		$tam = $tam[0];
	}
	else
	{
		$tam = "0";
	}

#---------------------Mapping the Morph output tags with generator
	if($cat[0] eq "pn")
	{
		$cat[0] = "P";
	}
	if($cat[0] eq "adj")
	{
		$cat[0] = "Adj";
	}
#--------------------------------------------------------
	if($gen[0] eq "" or ($gen[0] ne "m" and $gen[0] ne "f"))
	{
		$gen[0] = "m";
	}


	if($num[0] eq "sg")
	{
		$num[0] = "s";
	}
	elsif($num[0] eq "pl")
	{
		$num[0] = "p";
	}
	else
	{
		$num[0] = "s";
	}


	if($per[0] eq "1")
	{
		$per[0] = "u";
	}
	elsif($per[0] eq "2")
	{
		$per[0] = "m";
	}
	elsif($per[0] eq "3")
	{
		$per[0] = "a";
	}
	else
	{
		$per[0] = "a";
	}
	$case = $cases[0];
	if($case eq "o" and $cat[0] eq "P")
	{
		if($tam eq "" or $tam eq "0")
		{
			$tam = "1";
		}
	}
	if($case eq "o" and $cat[0] eq "Adj")
	{
		if($tam eq "" or $tam eq "0")
		{
			$tam = "1";
		}
	}

	if($cat[0] eq "psp" and $root eq "kA")
	{
		if($gen[0] eq "f")
		{
			$outline = "kI";
		}
		elsif(($num[0] eq "s" and $case eq "o") or $num[0] eq "p" )
		{
			$outline = "ke";
		}
		else
		{
			$outline = "kA";
		}
	}
	else
	{
		if($case eq "")
		{
			$case = "o";
		}
		if(@gen[0] ne "")
		{
			$input = $root." ".$cat[0]." $gen[0] $num[0] $per[0] $case ".$tam;
		}
		else 
		{
			$input = $root." ".$cat[0]." m $num[0] $per[0] $case ".$tam;
		}


		open(out2,">/tmp/hindi_gen_mid.tmp1$$");
		print out2 $input."\n";
#	print  STDERR $input."\n";
		system("gen/hnd_gen.out ON NOT < /tmp/hindi_gen_mid.tmp1$$ > /tmp/hindi_gen_mid.tmp$$ ");
		open(out1,"/tmp/hindi_gen_mid.tmp$$");

		$outline = <out1>;
		system("rm -rf /tmp/hindi_gen_mid.tmp1$$ /tmp/hindi_gen_mid.tmp$$");
		chomp($outline);
		$outline=~s/^\s*//g;
		$outline=~s/\@//g;
		$outline=~s/\{.*//g;
		$outline=~s/\_0$//g;
		$outline=~s/\_1$//g;
		$outline=~s/1$//g;
	}

	if($outline ne "" and $cat[0] ne "punc" and $cat[0] ne "adv")
	{
		print $outline."\n";
	}
	else
	{
		print $root."\n";
	}
}
